﻿Public Class SP_TriGia
    Dim cn As New DatabaseConnect
    Dim dt As DataTable
    Private Sub SP_TriGia_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dt = New DataTable()
        dt = cn.GetData("select * from SanPham_TriGia")
        dgv.DataSource = dt
    End Sub
    Private Sub btnCN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCN.Click
        Dim response As MsgBoxResult
        MsgBox("Cập nhật giá mới ?", MsgBoxStyle.YesNo, "Thông báo")
        If response = MsgBoxResult.Yes Then
            For Each row As DataGridViewRow In dgv.Rows
                If Not row.IsNewRow Then
                    cn.Execute("update SanPham_TriGia set trigia =" + row.Cells(1).Value + " where trigiaID = " + row.Cells(0).Value + "")
                Else
                    cn.Execute("insert into SanPham_TriGia(trigiaID, trigia) values(NULL," + row.Cells(1).Value + ")")
                End If
            Next
            dt = New DataTable()
            dt = cn.GetData("select * from SanPham_TriGia")
            dgv.DataSource = dt
        Else
            Return
        End If
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        dgv.Rows.Add()
    End Sub
End Class